package com.fc.v2.service;

import java.util.Date;
import java.util.List;
import java.util.Arrays;

import com.fc.v2.mapper.auto.SysDepartmentMapper;
import com.fc.v2.model.auto.SysDepartment;
import com.fc.v2.model.auto.TsysUser;
import com.fc.v2.shiro.util.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.util.StrUtil;
import com.fc.v2.common.base.BaseService;
import com.fc.v2.common.support.ConvertUtil;
import com.fc.v2.mapper.auto.YmjzMapper;
import com.fc.v2.model.auto.Ymjz;
import com.fc.v2.model.auto.YmjzExample;
import com.fc.v2.model.custom.Tablepar;
import com.fc.v2.util.SnowflakeIdWorker;
import com.fc.v2.util.StringUtils;

/**
 * YmjzService
 *
 * @author fuce_自动生成
 * @Title: YmjzService.java 
 * @Package com.fc.v2.service 
 * @email ${email}
 * @date 2022-03-28 16:23:42  
 **/
@Service
public class YmjzService implements BaseService<Ymjz, YmjzExample> {
    @Autowired
    private YmjzMapper ymjzMapper;

    @Autowired
    private SysDepartmentMapper sysDepartmentMapper;

    /**
     * 分页查询
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    public PageInfo<Ymjz> list(Tablepar tablepar, Ymjz ymjz) {
        YmjzExample testExample = new YmjzExample();
        //搜索
        TsysUser tsysUser = ShiroUtils.getUser();
        if (StrUtil.isNotEmpty(tablepar.getSearchText())) {//小窗体
            testExample.createCriteria().andLikeQuery2(tablepar.getSearchText());
        } else {//大搜索
            testExample.createCriteria().andLikeQuery(ymjz);
        }

        if (tsysUser != null && tsysUser.getDepId().intValue() != 1) {
            SysDepartment sysDepartment = sysDepartmentMapper.selectByPrimaryKey(tsysUser.getDepId());
            testExample.or().andBmEqualTo(sysDepartment.getDeptName());
        }

        //表格排序
        //if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
        //	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
        //}else{
//	        	testExample.setOrderByClause("id ASC");
        //}
        PageHelper.startPage(tablepar.getPage(), tablepar.getLimit());
        List<Ymjz> list = ymjzMapper.selectByExample(testExample);
        PageInfo<Ymjz> pageInfo = new PageInfo<Ymjz>(list);
        return pageInfo;
    }

    @Override
    public int deleteByPrimaryKey(String ids) {

        Integer[] integers = ConvertUtil.toIntArray(",", ids);
        List<Integer> stringB = Arrays.asList(integers);
        YmjzExample example = new YmjzExample();
        example.createCriteria().andIdIn(stringB);
        return ymjzMapper.deleteByExample(example);


    }


    @Override
    public Ymjz selectByPrimaryKey(String id) {

        Integer id1 = Integer.valueOf(id);
        return ymjzMapper.selectByPrimaryKey(id1);

    }


    @Override
    public int updateByPrimaryKeySelective(Ymjz record) {
        String name = ShiroUtils.getLoginName();
        record.setByname(name);
        record.setUpdateTime(new Date());
        return ymjzMapper.updateByPrimaryKeySelective(record);
    }


    /**
     * 添加
     */
    @Override
    public int insertSelective(Ymjz record) {
        String name = ShiroUtils.getLoginName();
        record.setByname(name);
        record.setCreateTime(new Date());
        record.setId(null);


        return ymjzMapper.insertSelective(record);
    }


    @Override
    public int updateByExampleSelective(Ymjz record, YmjzExample example) {

        return ymjzMapper.updateByExampleSelective(record, example);
    }


    @Override
    public int updateByExample(Ymjz record, YmjzExample example) {

        return ymjzMapper.updateByExample(record, example);
    }

    @Override
    public List<Ymjz> selectByExample(YmjzExample example) {

        return ymjzMapper.selectByExample(example);
    }


    @Override
    public long countByExample(YmjzExample example) {

        return ymjzMapper.countByExample(example);
    }


    @Override
    public int deleteByExample(YmjzExample example) {

        return ymjzMapper.deleteByExample(example);
    }

    /**
     * 修改权限状态展示或者不展示
     *
     * @param ymjz
     * @return
     */
    public int updateVisible(Ymjz ymjz) {
        return ymjzMapper.updateByPrimaryKeySelective(ymjz);
    }


}
